﻿using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Drawing;
using System.Data;
using System.Text;
using System.Linq;
using System.Threading.Tasks;
using System.Windows.Forms;
using DevExpress.XtraEditors;
using System.Drawing.Drawing2D;
using System.IO.Ports;
using SerialPortHelperLib;
using XChipTool.Enties;
using System.Runtime.InteropServices;
using System.Configuration;
using XChip_Common;
using BinAnalysisHelp;

namespace XChipTool
{
    public partial class XChip_Lite_HDR : DevExpress.XtraEditors.XtraUserControl
    {

        #region 全局变量
        addressregisterManager addrDal;
        //串口
        public SerialPort sPortTemp;
        //是否在获取数据
        private bool isRead = false;
        private bool isWrite = false;
        List<addressregister> hdrList = new List<addressregister>();

        private addressregisterManager aBll;
        //记录是否使用USB设备读写
        public bool IsUsbOpen = false;
        //记录是否使用I2C设备读写
        public bool m_open = false;

        private List<addressregister> XChipHDR;

        private XChip_Lite_HDR_Ae xChip_HDR_Ae;

        private static XChip_Lite_HDR _instance;
        public static XChip_Lite_HDR Instance(SerialPort _sPortTemp, addressregisterManager _aBll)
        {
            if (_instance == null)
            {
                _instance = new XChip_Lite_HDR(_sPortTemp, _aBll);
            }
            return _instance;
        }
        #endregion
        public XChip_Lite_HDR()
        {

            InitializeComponent();
        }
        public XChip_Lite_HDR(SerialPort _sPortTemp, addressregisterManager _aBll)
        {
            sPortTemp = _sPortTemp;
            aBll = _aBll;
            XChipHDR = aBll.GetList(c => c.ChipType == ConfigurationManager.AppSettings["xc151_ChipType"] && (c.Classify == "HDR"));
            InitializeComponent();

        }

        private void CheckMethod()
        {
            //#region 勾选框获取
            ////combine mode 0:normal mode; 1:sensor combine mode; 2:2 frame combine mode; 3:3 frame combine mode  
            //var combine = GetRegister("combine_mode_en", hdrList);
            //if (combine == 0x80)
            //{
            //    combineRadio.SelectedIndex = 0;
            //}
            //else
            //{
            //    combineRadio.SelectedIndex = 1;
            //}
            //combineRadio.SelectedIndex = (int)((combine >> 6) & 0x03);

            //if (((combine>>6)&0x03)==0)
            //{

            //}
            //else if (((combine >> 6) & 0x03) == 1)
            //{

            //}
            //else if (((combine >> 6) & 0x03) == 2)
            //{

            //}
            //else if (((combine >> 6) & 0x03) == 3)
            //{

            //}


            //Scene_Recognition_en
            //if (((SerialSend.ReadRegister((Convert.ToUInt32(hdrList.Where(c => c.NameType == "scene_recognition").First().Address, 16)), sPortTemp)) & 0x01) == 1)
            //{
            //    Scene_Recognition_en.CheckState = CheckState.Checked;
            //}
            //else
            //{
            //    Scene_Recognition_en.CheckState = CheckState.Unchecked;
            //}
            //Decowprssion_en [4]


            //Log_Combine_en [0]

            //Compression_en [5]
            //if ((((GetRegister("compression_in_en", hdrList)) >> 5) & 0x01) == 1)
            //{
            //    Compression_en.CheckState = CheckState.Checked;
            //}
            //else
            //{
            //    Compression_en.CheckState = CheckState.Unchecked;
            //}
            //YUV_Gamma_en
            //if (((SerialSend.ReadRegister((Convert.ToUInt32(hdrList.Where(c => c.NameType == "yuv_gamma").First().Address, 16)), sPortTemp)) & 0x01) == 1)
            //{
            //    YUV_Gamma_en.CheckState = CheckState.Checked;
            //}
            //else
            //{
            //    YUV_Gamma_en.CheckState = CheckState.Unchecked;
            //}

            //Log_Gamma_en [3]
            //if ((((GetRegister("Log_Gamma_en", hdrList)) >> 3) & 0x01) == 1)
            //{
            //    Log_Gamma_en.CheckState = CheckState.Checked;
            //}
            //else
            //{
            //    Log_Gamma_en.CheckState = CheckState.Unchecked;
            //}

            ////Normalize_en
            //if ((((GetRegister("Normalize_en", hdrList)) >> 6) & 0x01) == 1)
            //{
            //    Normalize_en.CheckState = CheckState.Checked;
            //}
            //else
            //{
            //    Normalize_en.CheckState = CheckState.Unchecked;
            //}

            ////Gamma_Correetion_en [2]
            //if ((((GetRegister("gamma_correction", hdrList)) >> 2) & 0x01) == 1)
            //{
            //    Gamma_Correetion_en.CheckState = CheckState.Checked;
            //}
            //else
            //{
            //    Gamma_Correetion_en.CheckState = CheckState.Unchecked;
            //}



            //single_frames

            //continuous frames


            //#endregion
        }

        private long GetRegister(string NType, List<addressregister> list)
        {
            long getTemp = -1;
            var ntList = list.Where(c => c.NameType.ToLower().Contains(NType.ToLower())).OrderBy(c => c.Sorting).ToList();
            switch (ntList.Count())
            {
                case 1:
                    getTemp = SerialSend.ReadRegister(Convert.ToUInt32(ntList[0].Address, 16), sPortTemp);
                    break;
                case 2:
                    {
                        var nHigh = SerialSend.ReadRegister(Convert.ToUInt32(ntList[0].Address, 16), sPortTemp);
                        var nLow = SerialSend.ReadRegister(Convert.ToUInt32(ntList[1].Address, 16), sPortTemp);
                        getTemp = (nHigh << 8 & 0xff00) | (nLow & 0xff);
                    }
                    break;
                case 3:
                    {
                        var nHigh = SerialSend.ReadRegister(Convert.ToUInt32(ntList[0].Address, 16), sPortTemp);
                        var nMiddle = SerialSend.ReadRegister(Convert.ToUInt32(ntList[1].Address, 16), sPortTemp);
                        var nLow = SerialSend.ReadRegister(Convert.ToUInt32(ntList[2].Address, 16), sPortTemp);
                        getTemp = (nHigh << 16 & 0xff0000) | ((nMiddle << 8 & 0xff00)) | (nLow & 0xff);
                    }
                    break;
                default:
                    break;
            }
            return getTemp;
        }
        private long GetRegister(string nameType)
        {

            if (!sPortTemp.IsOpen && !IsUsbOpen && !m_open)
            {
                DevExpress.XtraEditors.XtraMessageBox.Show("可用端口未打开");
                return -1;
            }

            if (XChipHDR.Exists(c => c.NameType.ToLower() == nameType.ToLower()))
            {
                var model = XChipHDR.Find(c => c.NameType.ToLower() == nameType.ToLower());
                var Val = SerialSend.ReadRegister(Convert.ToUInt32(model.Address, 16), sPortTemp);
                if (model.ControlType.Contains("1"))
                {
                    return BitsHelp.GetBitsCheckedToBool(model.Bits, model.Hex, Val.ToString("X2"));
                }
                else
                {
                    return BitsHelp.GetBitsToUint(model.Bits, model.Hex, Val.ToString("X2"));
                }
            }
            else
            {
                DevExpress.XtraEditors.XtraMessageBox.Show($"未找到{nameType}"); return -1;
            }


        }
        private void SetRegister(string NType, ulong add, List<addressregister> list)
        {
            var ntList = list.Where(c => c.NameType.ToLower().Contains(NType.ToLower())).OrderBy(c => c.Sorting).ToList();
            if (IsUsbOpen)
            {
                bool isbool;
                uint addrstr;
                switch (ntList.Count())
                {
                    case 1:

                        if (IntPtr.Size == 8)
                        {
                            isbool = XChipUSB.UsbRegisterWrite64((uint)Convert.ToUInt32(ntList[0].Address, 16), (uint)add, false);
                        }
                        else
                        {
                            isbool = XChipUSB.UsbRegisterWrite86((uint)Convert.ToUInt32(ntList[0].Address, 16), (uint)add, false);
                        }
                        addrstr = Convert.ToUInt32(ntList[0].Address, 16);
                        SerialSend.Sendser("W:0x" + addrstr.ToString("X2"), add.ToString("X2"));
                        //SerialSend.WriteRegister(0x21, Convert.ToUInt32(ntList[0].Address, 16), add, sPortTemp);
                        if (null != BinHelp.usbList)
                        {
                            uint pVule = 0x0;
                            isbool = false;
                            if (IntPtr.Size == 8)
                            {
                                isbool = XChipUSB.UsbRegisterRead64(BinHelp.CurrentSize, ref pVule, true);
                                SerialSend.Sendser("R:0x" + (BinHelp.CurrentSize).ToString("X2"), pVule.ToString("X2"));


                            }
                            else
                            {
                                isbool = XChipUSB.UsbRegisterRead86(BinHelp.CurrentSize, ref pVule, true);
                                SerialSend.Sendser("R:0x" + (BinHelp.CurrentSize).ToString("X2"), pVule.ToString("X2"));
                            }
                            var chang = (int)(pVule >> 16); // 使用右移16位操作来获取高16位  
                            var kuang = (int)(pVule & 0xFFFF); // 使用位与操作来获取低16位  

                            BinHelp.SstBinUsbUpdateData(ref BinHelp.BinList, ntList[0].Address, add.ToString("X"), chang, kuang);
                        }
                        break;
                    case 2:
                        {
                            if (NType.ToLower().Contains("node_list") && ((add >> 8) & 0xff) > 0x1f)
                            {

                                if (IntPtr.Size == 8)
                                {
                                    isbool = XChipUSB.UsbRegisterWrite64((uint)Convert.ToUInt32(ntList[0].Address, 16), (uint)0x1f, false);
                                }
                                else
                                {
                                    isbool = XChipUSB.UsbRegisterWrite86((uint)Convert.ToUInt32(ntList[0].Address, 16), (uint)0x1f, false);
                                }
                                addrstr = Convert.ToUInt32(ntList[0].Address, 16);
                                SerialSend.Sendser("W:0x" + addrstr.ToString("X2"), 0x1f.ToString("X2"));
                                if (null != BinHelp.usbList)
                                {
                                    uint pVule = 0x0;
                                    isbool = false;
                                    if (IntPtr.Size == 8)
                                    {
                                        isbool = XChipUSB.UsbRegisterRead64(BinHelp.CurrentSize, ref pVule, true);
                                        SerialSend.Sendser("R:0x" + (BinHelp.CurrentSize).ToString("X2"), pVule.ToString("X2"));


                                    }
                                    else
                                    {
                                        isbool = XChipUSB.UsbRegisterRead86(BinHelp.CurrentSize, ref pVule, true);
                                        SerialSend.Sendser("R:0x" + (BinHelp.CurrentSize).ToString("X2"), pVule.ToString("X2"));
                                    }
                                    var chang = (int)(pVule >> 16); // 使用右移16位操作来获取高16位  
                                    var kuang = (int)(pVule & 0xFFFF); // 使用位与操作来获取低16位  

                                    BinHelp.SstBinUsbUpdateData(ref BinHelp.BinList, ntList[0].Address, (0x1f).ToString("X"), chang, kuang);
                                }
                            }
                            else
                            {
                                if (IntPtr.Size == 8)
                                {
                                    isbool = XChipUSB.UsbRegisterWrite64((uint)Convert.ToUInt32(ntList[0].Address, 16), (uint)((add >> 8) & 0xff), false);
                                }
                                else
                                {
                                    isbool = XChipUSB.UsbRegisterWrite86((uint)Convert.ToUInt32(ntList[0].Address, 16), (uint)((add >> 8) & 0xff), false);
                                }
                                addrstr = Convert.ToUInt32(ntList[0].Address, 16);
                                SerialSend.Sendser("W:0x" + addrstr.ToString("X2"), ((add >> 8) & 0xff).ToString("X2"));
                                if (null != BinHelp.usbList)
                                {
                                    uint pVule = 0x0;
                                    isbool = false;
                                    if (IntPtr.Size == 8)
                                    {
                                        isbool = XChipUSB.UsbRegisterRead64(BinHelp.CurrentSize, ref pVule, true);
                                        SerialSend.Sendser("R:0x" + (BinHelp.CurrentSize).ToString("X2"), pVule.ToString("X2"));


                                    }
                                    else
                                    {
                                        isbool = XChipUSB.UsbRegisterRead86(BinHelp.CurrentSize, ref pVule, true);
                                        SerialSend.Sendser("R:0x" + (BinHelp.CurrentSize).ToString("X2"), pVule.ToString("X2"));
                                    }
                                    var chang = (int)(pVule >> 16); // 使用右移16位操作来获取高16位  
                                    var kuang = (int)(pVule & 0xFFFF); // 使用位与操作来获取低16位  

                                    BinHelp.SstBinUsbUpdateData(ref BinHelp.BinList, ntList[0].Address, ((add >> 8) & 0xff).ToString("X"), chang, kuang);
                                }

                            }
                            if (NType.ToLower().Contains("gain_list") && ((add >> 8) & 0xff) > 0x03)
                            {
                                if (IntPtr.Size == 8)
                                {
                                    isbool = XChipUSB.UsbRegisterWrite64((uint)Convert.ToUInt32(ntList[0].Address, 16), (uint)0x03, false);
                                }
                                else
                                {
                                    isbool = XChipUSB.UsbRegisterWrite86((uint)Convert.ToUInt32(ntList[0].Address, 16), (uint)0x03, false);
                                }
                                addrstr = Convert.ToUInt32(ntList[0].Address, 16);
                                SerialSend.Sendser("W:0x" + addrstr.ToString("X2"), 0x03.ToString("X2"));
                                //SerialSend.WriteRegister(0x21, Convert.ToUInt32(ntList[0].Address, 16), 0x03, sPortTemp);
                                if (null != BinHelp.usbList)
                                {
                                    uint pVule = 0x0;
                                    isbool = false;
                                    if (IntPtr.Size == 8)
                                    {
                                        isbool = XChipUSB.UsbRegisterRead64(BinHelp.CurrentSize, ref pVule, true);
                                        SerialSend.Sendser("R:0x" + (BinHelp.CurrentSize).ToString("X2"), pVule.ToString("X2"));


                                    }
                                    else
                                    {
                                        isbool = XChipUSB.UsbRegisterRead86(BinHelp.CurrentSize, ref pVule, true);
                                        SerialSend.Sendser("R:0x" + (BinHelp.CurrentSize).ToString("X2"), pVule.ToString("X2"));
                                    }
                                    var chang = (int)(pVule >> 16); // 使用右移16位操作来获取高16位  
                                    var kuang = (int)(pVule & 0xFFFF); // 使用位与操作来获取低16位  

                                    BinHelp.SstBinUsbUpdateData(ref BinHelp.BinList, ntList[0].Address, (0x03).ToString("X"), chang, kuang);
                                }
                            }
                            else
                            {
                                if (IntPtr.Size == 8)
                                {
                                    isbool = XChipUSB.UsbRegisterWrite64((uint)Convert.ToUInt32(ntList[0].Address, 16), (uint)((add >> 8) & 0xff), false);
                                }
                                else
                                {
                                    isbool = XChipUSB.UsbRegisterWrite86((uint)Convert.ToUInt32(ntList[0].Address, 16), (uint)((add >> 8) & 0xff), false);
                                }
                                addrstr = Convert.ToUInt32(ntList[0].Address, 16);
                                SerialSend.Sendser("W:0x" + addrstr.ToString("X2"), ((add >> 8) & 0xff).ToString("X2"));
                                //SerialSend.WriteRegister(0x21, Convert.ToUInt32(ntList[0].Address, 16), (add >> 8) & 0xff, sPortTemp);
                                if (null != BinHelp.usbList)
                                {
                                    uint pVule = 0x0;
                                    isbool = false;
                                    if (IntPtr.Size == 8)
                                    {
                                        isbool = XChipUSB.UsbRegisterRead64(BinHelp.CurrentSize, ref pVule, true);
                                        SerialSend.Sendser("R:0x" + (BinHelp.CurrentSize).ToString("X2"), pVule.ToString("X2"));


                                    }
                                    else
                                    {
                                        isbool = XChipUSB.UsbRegisterRead86(BinHelp.CurrentSize, ref pVule, true);
                                        SerialSend.Sendser("R:0x" + (BinHelp.CurrentSize).ToString("X2"), pVule.ToString("X2"));
                                    }
                                    var chang = (int)(pVule >> 16); // 使用右移16位操作来获取高16位  
                                    var kuang = (int)(pVule & 0xFFFF); // 使用位与操作来获取低16位  

                                    BinHelp.SstBinUsbUpdateData(ref BinHelp.BinList, ntList[0].Address, ((add >> 8) & 0xff).ToString("X"), chang, kuang);
                                }
                            }
                            if (IntPtr.Size == 8)
                            {
                                isbool = XChipUSB.UsbRegisterWrite64((uint)Convert.ToUInt32(ntList[1].Address, 16), (uint)(add & 0xff), false);
                            }
                            else
                            {
                                isbool = XChipUSB.UsbRegisterWrite86((uint)Convert.ToUInt32(ntList[1].Address, 16), (uint)(add & 0xff), false);
                            }
                            addrstr = Convert.ToUInt32(ntList[1].Address, 16);
                            SerialSend.Sendser("W:0x" + addrstr.ToString("X2"), (add & 0xff).ToString("X2"));
                            //SerialSend.WriteRegister(0x21, Convert.ToUInt32(ntList[1].Address, 16), add & 0xff, sPortTemp);
                            if (null != BinHelp.usbList)
                            {
                                uint pVule = 0x0;
                                isbool = false;
                                if (IntPtr.Size == 8)
                                {
                                    isbool = XChipUSB.UsbRegisterRead64(BinHelp.CurrentSize, ref pVule, true);
                                    SerialSend.Sendser("R:0x" + (BinHelp.CurrentSize).ToString("X2"), pVule.ToString("X2"));


                                }
                                else
                                {
                                    isbool = XChipUSB.UsbRegisterRead86(BinHelp.CurrentSize, ref pVule, true);
                                    SerialSend.Sendser("R:0x" + (BinHelp.CurrentSize).ToString("X2"), pVule.ToString("X2"));
                                }
                                var chang = (int)(pVule >> 16); // 使用右移16位操作来获取高16位  
                                var kuang = (int)(pVule & 0xFFFF); // 使用位与操作来获取低16位  

                                BinHelp.SstBinUsbUpdateData(ref BinHelp.BinList, ntList[1].Address, (add & 0xff).ToString("X"), chang, kuang);
                            }

                        }
                        break;
                    case 3:
                        {
                            if (IntPtr.Size == 8)
                            {
                                isbool = XChipUSB.UsbRegisterWrite64((uint)Convert.ToUInt32(ntList[2].Address, 16), (uint)(add & 0xff), false);
                                isbool = XChipUSB.UsbRegisterWrite64((uint)Convert.ToUInt32(ntList[1].Address, 16), (uint)((add >> 8) & 0xff), false);
                                isbool = XChipUSB.UsbRegisterWrite64((uint)Convert.ToUInt32(ntList[0].Address, 16), (uint)((add >> 16) & 0xff), false);
                            }
                            else
                            {
                                isbool = XChipUSB.UsbRegisterWrite86((uint)Convert.ToUInt32(ntList[2].Address, 16), (uint)(add & 0xff), false);
                                isbool = XChipUSB.UsbRegisterWrite86((uint)Convert.ToUInt32(ntList[1].Address, 16), (uint)((add >> 8) & 0xff), false);
                                isbool = XChipUSB.UsbRegisterWrite86((uint)Convert.ToUInt32(ntList[0].Address, 16), (uint)((add >> 16) & 0xff), false);
                            }
                            addrstr = Convert.ToUInt32(ntList[2].Address, 16);
                            SerialSend.Sendser("W:0x" + addrstr.ToString("X2"), (add & 0xff).ToString("X2"));
                            addrstr = Convert.ToUInt32(ntList[1].Address, 16);
                            SerialSend.Sendser("W:0x" + addrstr.ToString("X2"), ((add >> 8) & 0xff).ToString("X2"));
                            addrstr = Convert.ToUInt32(ntList[0].Address, 16);
                            SerialSend.Sendser("W:0x" + addrstr.ToString("X2"), ((add >> 16) & 0xff).ToString("X2"));
                            //SerialSend.WriteRegister(0x21, Convert.ToUInt32(ntList[2].Address, 16), add & 0xff, sPortTemp);
                            //SerialSend.WriteRegister(0x21, Convert.ToUInt32(ntList[1].Address, 16), (add >> 8) & 0xff, sPortTemp);
                            //SerialSend.WriteRegister(0x21, Convert.ToUInt32(ntList[0].Address, 16), (add >> 16) & 0xff, sPortTemp);
                            if (null != BinHelp.usbList)
                            {
                                uint pVule = 0x0;
                                isbool = false;
                                if (IntPtr.Size == 8)
                                {
                                    isbool = XChipUSB.UsbRegisterRead64(BinHelp.CurrentSize, ref pVule, true);
                                    SerialSend.Sendser("R:0x" + (BinHelp.CurrentSize).ToString("X2"), pVule.ToString("X2"));


                                }
                                else
                                {
                                    isbool = XChipUSB.UsbRegisterRead86(BinHelp.CurrentSize, ref pVule, true);
                                    SerialSend.Sendser("R:0x" + (BinHelp.CurrentSize).ToString("X2"), pVule.ToString("X2"));
                                }
                                var chang = (int)(pVule >> 16); // 使用右移16位操作来获取高16位  
                                var kuang = (int)(pVule & 0xFFFF); // 使用位与操作来获取低16位  

                                BinHelp.SstBinUsbUpdateData(ref BinHelp.BinList, ntList[2].Address, (add & 0xff).ToString("X"), chang, kuang);
                                BinHelp.SstBinUsbUpdateData(ref BinHelp.BinList, ntList[1].Address, ((add >> 8) & 0xff).ToString("X"), chang, kuang);
                                BinHelp.SstBinUsbUpdateData(ref BinHelp.BinList, ntList[0].Address, ((add >> 16) & 0xff).ToString("X"), chang, kuang);
                            }
                        }
                        break;
                    default:
                        break;
                }
            }
            else
            {
                switch (ntList.Count())
                {
                    case 1:
                        SerialSend.WriteRegister(Convert.ToUInt32(ntList[0].Address, 16), add, sPortTemp);
                        if (null != BinHelp.lspList)
                        { //编写Bin更新数据
                            var temp = SerialSend.ReadRegister(BinHelp.BootSettingIdx, sPortTemp);
                            BinHelp.SetBinUpdateData(ref BinHelp.BinList, ntList[0].Address, (add).ToString("X"), (uint)temp);
                        }
                        break;
                    case 2:
                        {
                            if (NType.ToLower().Contains("node_list") && ((add >> 8) & 0xff) > 0x1f)
                            {
                                SerialSend.WriteRegister(Convert.ToUInt32(ntList[0].Address, 16), 0x1f, sPortTemp);
                                if (null != BinHelp.lspList)
                                { //编写Bin更新数据
                                    var temp = SerialSend.ReadRegister(BinHelp.BootSettingIdx, sPortTemp);
                                    BinHelp.SetBinUpdateData(ref BinHelp.BinList, ntList[0].Address, (0x1f).ToString("X"), (uint)temp);
                                }
                            }
                            else
                            {
                                SerialSend.WriteRegister(Convert.ToUInt32(ntList[0].Address, 16), (add >> 8) & 0xff, sPortTemp);
                                if (null != BinHelp.lspList)
                                { //编写Bin更新数据
                                    var temp = SerialSend.ReadRegister(BinHelp.BootSettingIdx, sPortTemp);
                                    BinHelp.SetBinUpdateData(ref BinHelp.BinList, ntList[0].Address, ((add >> 8) & 0xff).ToString("X"), (uint)temp);
                                }
                            }
                            if (NType.ToLower().Contains("gain_list") && ((add >> 8) & 0xff) > 0x03)
                            {
                                SerialSend.WriteRegister(Convert.ToUInt32(ntList[0].Address, 16), 0x03, sPortTemp);
                                if (null != BinHelp.lspList)
                                { //编写Bin更新数据
                                    var temp = SerialSend.ReadRegister(BinHelp.BootSettingIdx, sPortTemp);
                                    BinHelp.SetBinUpdateData(ref BinHelp.BinList, ntList[0].Address, (0x03).ToString("X"), (uint)temp);
                                }
                            }
                            else
                            {
                                SerialSend.WriteRegister(Convert.ToUInt32(ntList[0].Address, 16), (add >> 8) & 0xff, sPortTemp);
                                if (null != BinHelp.lspList)
                                { //编写Bin更新数据
                                    var temp = SerialSend.ReadRegister(BinHelp.BootSettingIdx, sPortTemp);
                                    BinHelp.SetBinUpdateData(ref BinHelp.BinList, ntList[0].Address, ((add >> 8) & 0xff).ToString("X"), (uint)temp);
                                }
                            }
                            SerialSend.WriteRegister(Convert.ToUInt32(ntList[1].Address, 16), add & 0xff, sPortTemp);
                            if (null != BinHelp.lspList)
                            { //编写Bin更新数据
                                var temp = SerialSend.ReadRegister(BinHelp.BootSettingIdx, sPortTemp);
                                BinHelp.SetBinUpdateData(ref BinHelp.BinList, ntList[1].Address, (add & 0xff).ToString("X"), (uint)temp);
                            }

                        }
                        break;
                    case 3:
                        {
                            SerialSend.WriteRegister(Convert.ToUInt32(ntList[2].Address, 16), add & 0xff, sPortTemp);
                            SerialSend.WriteRegister(Convert.ToUInt32(ntList[1].Address, 16), (add >> 8) & 0xff, sPortTemp);
                            SerialSend.WriteRegister(Convert.ToUInt32(ntList[0].Address, 16), (add >> 16) & 0xff, sPortTemp);
                            if (null != BinHelp.lspList)
                            { //编写Bin更新数据
                                var temp = SerialSend.ReadRegister(BinHelp.BootSettingIdx, sPortTemp);
                                BinHelp.SetBinUpdateData(ref BinHelp.BinList, ntList[2].Address, (add & 0xff).ToString("X"), (uint)temp);
                                BinHelp.SetBinUpdateData(ref BinHelp.BinList, ntList[1].Address, ((add >> 8) & 0xff).ToString("X"), (uint)temp);
                                BinHelp.SetBinUpdateData(ref BinHelp.BinList, ntList[0].Address, ((add >> 16) & 0xff).ToString("X"), (uint)temp);
                            }
                        }
                        break;
                    default:
                        break;
                }
            }

        }


    

        private void comb_weight_LS_00_KeyDown(object sender, KeyEventArgs e)
        {
            if (e.KeyCode == Keys.Enter)
            {
                comb_weight_LS_00_Leave(sender, null);

            }
        }

        private void comb_weight_LS_00_Leave(object sender, EventArgs e)
        {
            if (isWrite) return;
            if (hdrList.Count == 0)
            {
                if (null == addrDal)
                {
                    addrDal = new addressregisterManager();
                }
                hdrList = addrDal.GetList(c => c.Classify.Contains("hdr"));
            }
            var combtxt = sender as TextEdit;
            if (Convert.ToInt32(combtxt.Text, 16) > 0x80)
            {
                combtxt.Text = "80";
            }
            //var mstr = modeSelRadio.SelectedIndex == 0 ? "hl" : "ll";
            var mstr = "hl";
            SetRegister($"comb_weight_LS_{mstr}_{combtxt.Tag.ToString()}", Convert.ToUInt32(combtxt.Text, 16), hdrList);


        }

        private void comb_weight_LSV_00_KeyDown(object sender, KeyEventArgs e)
        {
            if (e.KeyCode == Keys.Enter)
            {
                comb_weight_LSV_00_Leave(sender, null);
            }
        }

        private void comb_weight_LSV_00_Leave(object sender, EventArgs e)
        {
            if (isWrite) return;
            if (hdrList.Count == 0)
            {
                if (null == addrDal)
                {
                    addrDal = new addressregisterManager();
                }
                hdrList = addrDal.GetList(c => c.Classify.Contains("hdr"));
            }
            var combtxt = sender as TextEdit;
            if (Convert.ToInt32(combtxt.Text, 16) > 0x80)
            {
                combtxt.Text = "80";
            }
            //var mstr = modeSelRadio.SelectedIndex == 0 ? "hl" : "ll";
            var mstr = "hl";
            SetRegister($"comb_weight_LSV_{mstr}_{combtxt.Tag.ToString()}", Convert.ToUInt32(combtxt.Text, 16), hdrList);
        }



        private void tabPane1_SelectedPageIndexChanged(object sender, EventArgs e)
        {
            if (tabPane1.SelectedPageIndex == 1)
            {
                xChip_HDR_GAMMA1.sPortTemp = sPortTemp;
                xChip_HDR_GAMMA1.IsUsbOpen = IsUsbOpen;
            }
            if (tabPane1.SelectedPageIndex == 2)
            {
                xChip_HDR_Ae.sPortTemp = sPortTemp;
                xChip_HDR_Ae.IsUsbOpen = IsUsbOpen;
                //xChip_HDR_Ae1.aBll = aBll;
                //xChip_HDR_Ae1.XChipHDRAe = aBll.GetList(c => c.ChipType == ConfigurationManager.AppSettings["xc151_ChipType"] && (c.Classify == "HDR_AE" || c.Classify == "Common"));
            }
        }
        /// <summary>
        /// sensor status
        /// </summary>
        /// <param name="sender"></param>
        /// <param name="e"></param>
        private void simpleButton3_Click(object sender, EventArgs e)
        {

            List<string> listfiltration = new List<string> { "exp_ratio_LS_l", "exp_ratio_LS_h", "exp_line_L_l", "exp_line_L_m0", "exp_line_L_h", "gain_L_l", "gain_L_h", "exp_ratio_SV_h", "exp_ratio_SV_l", "exp_line_S_l", "exp_line_S_m0", "exp_line_S_h", "gain_S_l", "gain_S_h", "exp_line_V_l", "exp_line_V_h", "exp_line_V_m0", "gain_V_h", "gain_V_l", "combine_preferLong_str" };
            List<string> NameList = new List<string>();
            for (int i = 0; i < XChipHDR.Count; i++)
            {
                var type = AppHelper.NameTypeToString(XChipHDR[i].NameType);
                //加上单选框的_en
                if (XChipHDR[i].ControlType == "1")
                {
                    type = XChipHDR[i].NameType;
                }
                var col = this.Controls.Find(type, true);
                foreach (var item in col)
                {
                    if (NameList.Exists(c => c.Contains(type)))
                    {
                        continue;
                    }
                    else
                    {

                        //过滤掉指定寄存器
                        if (!listfiltration.Exists(c => c.Contains(item.Name.ToString())))
                        {
                            continue;
                        }
                        if (item is TextEdit)
                        {

                            var nList = XChipHDR.Where(c => c.NameType.ToLower().Contains(item.Name.ToString().ToLower()) && c.ControlType == "0").ToList();
                            if (nList.Count == 1)
                            {
                                var Val = SerialSend.ReadRegister(Convert.ToUInt32(nList[0].Address, 16), sPortTemp).ToString("X");
                                item.Text = BitsHelp.GetBitsToUint(nList[0].Bits, nList[0].Hex, Val).ToString("X");
                            }
                            else
                            {
                                var listsum = nList.Select(c => c.Address).Distinct().ToList();
                                string Val = string.Empty;
                                if (1 == listsum.Count())
                                {

                                }
                                else
                                {

                                }

                                //这里默认为是有多个寄存器  一个文本框的情况进行处理
                                if (nList.Exists(c => c.NameType.ToLower().Contains("_h")))
                                {
                                    Val += SerialSend.ReadRegister(Convert.ToUInt32(nList.Find(c => c.NameType.ToLower().Contains("_h")).Address, 16), sPortTemp).ToString("X2");
                                }
                                if (nList.Exists(c => c.NameType.ToLower().Contains("_m0")))
                                {
                                    Val += SerialSend.ReadRegister(Convert.ToUInt32(nList.Find(c => c.NameType.ToLower().Contains("_m0")).Address, 16), sPortTemp).ToString("X2");
                                }
                                if (nList.Exists(c => c.NameType.ToLower().Substring(c.NameType.Length - 2).Contains("_l")))
                                {
                                    Val += SerialSend.ReadRegister(Convert.ToUInt32(nList.Find(c => c.NameType.ToLower().Substring(c.NameType.Length - 2).Contains("_l")).Address, 16), sPortTemp).ToString("X2");
                                }
                                item.Text = Val;
                            }
                        }
                        else if (item is CheckEdit)
                        {
                            var nList = XChipHDR.Where(c => c.NameType.ToLower().Contains(item.Name.ToString().ToLower()) && c.ControlType == "1").ToList();
                            if (nList.Count == 1)
                            {
                                var Val = SerialSend.ReadRegister(Convert.ToUInt32(nList[0].Address, 16), sPortTemp).ToString("X");
                                (item as CheckEdit).Checked = BitsHelp.GetBitsCheckedToBool(nList[0].Bits, nList[0].Hex, Val) == 0;
                            }
                        }


                    }
                }
                NameList.Add(type);
            }
            //string Vals = string.Empty;
            //Vals += SerialSend.ReadRegister(Convert.ToUInt32(XChipHDR.Find(c=>c.NameType.Contains("gain_L_l")).Address,16), sPortTemp).ToString("X2");
            //Vals += SerialSend.ReadRegister(Convert.ToUInt32(XChipHDR.Find(c => c.NameType.Contains("gain_L_h")).Address, 16), sPortTemp).ToString("X2");
            //gain_L.Text = Vals;
        }



        private void simpleButton4_Click(object sender, EventArgs e)
        {
            //CheckMethod();
            //var H = SerialSend.ReadRegister(Convert.ToUInt32(XChipHDR.Find(c => c.NameType.ToLower() == ($"hdr_oer_l_h").ToLower()).Address, 16), sPortTemp).ToString("X2");
            //var L = SerialSend.ReadRegister(Convert.ToUInt32(XChipHDR.Find(c => c.NameType.ToLower() == ($"hdr_oer_l_l").ToLower()).Address, 16), sPortTemp).ToString("X2");

            //hdr_oer_l.Text = H + L;

            //H = SerialSend.ReadRegister(Convert.ToUInt32(XChipHDR.Find(c => c.NameType.ToLower() == ($"avgtext").ToLower()).Address, 16), sPortTemp).ToString("X2");
            //avgtext.Text = H;
            //H = SerialSend.ReadRegister(Convert.ToUInt32(XChipHDR.Find(c => c.NameType.ToLower() == ($"exp_ratio_LS_h").ToLower()).Address, 16), sPortTemp).ToString("X2");
            //L = SerialSend.ReadRegister(Convert.ToUInt32(XChipHDR.Find(c => c.NameType.ToLower() == ($"exp_ratio_LS_l").ToLower()).Address, 16), sPortTemp).ToString("X2");

            //exp_ratio_LS.Text = H + L;
            //H = SerialSend.ReadRegister(Convert.ToUInt32(XChipHDR.Find(c => c.NameType.ToLower() == ($"exp_ratio_SV_h").ToLower()).Address, 16), sPortTemp).ToString("X2");
            //L = SerialSend.ReadRegister(Convert.ToUInt32(XChipHDR.Find(c => c.NameType.ToLower() == ($"exp_ratio_SV_l").ToLower()).Address, 16), sPortTemp).ToString("X2");

            //exp_ratio_SV.Text = H + L;

            //H = SerialSend.ReadRegister(Convert.ToUInt32(XChipHDR.Find(c => c.NameType.ToLower() == ($"hist_thr_highlight_h").ToLower()).Address, 16), sPortTemp).ToString("X2");
            //L = SerialSend.ReadRegister(Convert.ToUInt32(XChipHDR.Find(c => c.NameType.ToLower() == ($"hist_thr_highlight_l").ToLower()).Address, 16), sPortTemp).ToString("X2");

            //hist_thr_highlight.Text = H + L;
        }
        private long GetHDRRegister(string nameType)
        {
            if (!sPortTemp.IsOpen && !IsUsbOpen && !m_open)
            {
                DevExpress.XtraEditors.XtraMessageBox.Show("可用端口未打开");
                return -1;
            }

            if (XChipHDR.Exists(c => c.NameType.ToLower() == nameType.ToLower()))
            {
                var model = XChipHDR.Find(c => c.NameType.ToLower() == nameType.ToLower());
                var Val = SerialSend.ReadRegister(Convert.ToUInt32(model.Address, 16), sPortTemp);
                if (model.ControlType.Contains("1"))
                {
                    return BitsHelp.GetBitsCheckedToBool(model.Bits, model.Hex, Val.ToString("X2"));
                }
                else
                {
                    return BitsHelp.GetBitsToUint(model.Bits, model.Hex, Val.ToString("X2"));
                }
            }
            else
            {
                DevExpress.XtraEditors.XtraMessageBox.Show($"未找到{nameType}"); return -1;
            }

        }

        private void SetHDRRegister(addressregister model, ulong add, bool isCheck = true)
        {
            if (isRead) return;
            if (IsUsbOpen)
            {
                if (null != BinHelp.usbList)
                {
                    uint pVule = 0x0;
                    var isbool = false;
                    if (IntPtr.Size == 8)
                    {
                        isbool = XChipUSB.UsbRegisterRead64(BinHelp.CurrentSize, ref pVule, true);
                        SerialSend.Sendser("R:0x" + (BinHelp.CurrentSize).ToString("X2"), pVule.ToString("X2"));


                    }
                    else
                    {
                        isbool = XChipUSB.UsbRegisterRead86(BinHelp.CurrentSize, ref pVule, true);
                        SerialSend.Sendser("R:0x" + (BinHelp.CurrentSize).ToString("X2"), pVule.ToString("X2"));
                    }
                    var chang = (int)(pVule >> 16); // 使用右移16位操作来获取高16位  
                    var kuang = (int)(pVule & 0xFFFF); // 使用位与操作来获取低16位  

                    BinHelp.SstBinUsbUpdateData(ref BinHelp.BinList, model.Address, add.ToString("X"), chang, kuang);
                }
            }
            else
            {
                if (!sPortTemp.IsOpen && !IsUsbOpen && !m_open)//串口检测
                {
                    DevExpress.XtraEditors.XtraMessageBox.Show("串口未打开");
                    return;
                }
                if (isRead) return;
                if (null != BinHelp.lspList)
                { //编写Bin更新数据
                    var temp = SerialSend.ReadRegister(BinHelp.BootSettingIdx, sPortTemp);
                    BinHelp.SetBinUpdateData(ref BinHelp.BinList, model.Address, add.ToString("X"), (uint)temp);
                }
            }
            SerialSend.WriteRegister(Convert.ToUInt32(model.Address, 16), add, sPortTemp);

        }

        private void panelControl13_Paint(object sender, PaintEventArgs e)
        {
            //float move = 20f;
            //float newX = panelControl6.Width - move;
            //float newY = panelControl6.Height - move;
            ////Y轴
            //PointF px1 = new PointF(move, move);
            //PointF px2 = new PointF(move, newY);
            //PointF px3 = new PointF(move - 10, newY);
            //Pen penAxis = new Pen(Brushes.Black, 1);
            //e.Graphics.DrawString("V_Y", new Font("宋体", 10f), Brushes.Black, px3);
            //penAxis.EndCap = System.Drawing.Drawing2D.LineCap.ArrowAnchor;
            //penAxis.CustomEndCap = new AdjustableArrowCap(4, 4, true);
            //e.Graphics.DrawLine(penAxis, px1, px2);
            //px1 = new PointF(move, move);
            //px2 = new PointF(newX, move);
            //px3 = new PointF(newX - 5, move - 15);
            //e.Graphics.DrawLine(penAxis, px1, px2);
            //e.Graphics.DrawString("F_Y", new Font("宋体", 10f), Brushes.Black, px3);
        }

        private void panelControl12_Paint(object sender, PaintEventArgs e)
        {
            //float move = 20f;
            //float newX = panelControl5.Width - move;
            //float newY = panelControl5.Height - move;
            ////Y轴
            //PointF px1 = new PointF(move, move);
            //PointF px2 = new PointF(move, newY);
            //PointF px3 = new PointF(move - 10, newY);
            //Pen penAxis = new Pen(Brushes.Black, 1);
            //e.Graphics.DrawString("S_Y", new Font("宋体", 10f), Brushes.Black, px3);
            //penAxis.EndCap = System.Drawing.Drawing2D.LineCap.ArrowAnchor;
            //penAxis.CustomEndCap = new AdjustableArrowCap(4, 4, true);
            //e.Graphics.DrawLine(penAxis, px1, px2);
            //px1 = new PointF(move, move);
            //px2 = new PointF(newX - 10, move);
            //px3 = new PointF(newX - 15, move - 15);
            //e.Graphics.DrawLine(penAxis, px1, px2);
            //e.Graphics.DrawString("L_Y", new Font("宋体", 10f), Brushes.Black, px3);
        }

        private void simpleButton8_Click(object sender, EventArgs e)
        {
            if (null == addrDal)
            {
                addrDal = new addressregisterManager();
            }
            isRead = true;
            if (hdrList.Count == 0)
            {
                hdrList = addrDal.GetList(c => c.Classify.Contains("hdr"));
            }
            WaitBefore.Start("读取中", "正在加载中", 10);

            //var modeSel = GetRegister("scene_mode", hdrList);
            //modeSelRadio.SelectedIndex = (int)(modeSel & 0x01);
            //scene_mode.Text = modeSel.ToString("X2");
            CheckMethod();
            //#region 文本框

            string nameType = string.Empty;

            List<string> NameList = new List<string>();
            for (int i = 0; i < XChipHDR.Count; i++)
            {
                if (XChipHDR[i].NameType.Contains("compression_list0"))
                {

                }
                var type = AppHelper.NameTypeToString(XChipHDR[i].NameType);
                //加上单选框的_en
                if (XChipHDR[i].ControlType == "1")
                {
                    type = XChipHDR[i].NameType;
                }
                var col = this.Controls.Find(type, true);

                foreach (var item in col)
                {
                    if (NameList.Exists(c => c == (type)))
                    {
                        continue;
                    }
                    else
                    {

                        if (item is TextEdit)
                        {

                            var nList = XChipHDR.Where(c => c.NameType.ToLower().Contains(item.Name.ToString().ToLower()) && c.ControlType == "0").ToList();
                            if (nList.Count == 1)
                            {
                                var Val = SerialSend.ReadRegister(Convert.ToUInt32(nList[0].Address, 16), sPortTemp).ToString("X");
                                item.Text = BitsHelp.GetBitsToUint(nList[0].Bits, nList[0].Hex, Val).ToString("X");
                            }
                            else
                            {
                                var listsum = nList.Select(c => c.Address).Distinct().ToList();
                                string Val = string.Empty;
                                if (1 == listsum.Count())
                                {

                                }
                                else
                                {

                                }

                                //这里默认为是有多个寄存器  一个文本框的情况进行处理
                                if (nList.Exists(c => c.NameType.ToLower().Contains("_h")))
                                {
                                    Val += SerialSend.ReadRegister(Convert.ToUInt32(nList.Find(c => c.NameType.ToLower().Contains("_h")).Address, 16), sPortTemp).ToString("X2");
                                }
                                if (nList.Exists(c => c.NameType.ToLower().Contains("_m0")))
                                {
                                    Val += SerialSend.ReadRegister(Convert.ToUInt32(nList.Find(c => c.NameType.ToLower().Contains("_m0")).Address, 16), sPortTemp).ToString("X2");
                                }

                                if (nList.Exists(c => c.NameType.ToLower().Substring(c.NameType.Length - 2).Contains("_l")))
                                {
                                    Val += SerialSend.ReadRegister(Convert.ToUInt32(nList.Find(c => c.NameType.ToLower().Substring(c.NameType.Length - 2).Contains("_l")).Address, 16), sPortTemp).ToString("X2");
                                }
                                item.Text = Val;
                            }
                        }
                        else if (item is CheckEdit)
                        {
                            var nList = XChipHDR.Where(c => c.NameType.ToLower().Contains(item.Name.ToString().ToLower()) && c.ControlType == "1").ToList();
                            if (nList.Count == 1)
                            {
                                var Val = SerialSend.ReadRegister(Convert.ToUInt32(nList[0].Address, 16), sPortTemp).ToString("X");
                                (item as CheckEdit).Checked = BitsHelp.GetBitsCheckedToBool(nList[0].Bits, nList[0].Hex, Val) == 0;
                            }
                        }


                    }
                }
                NameList.Add(type);
            }
            //string Vals = string.Empty;
            //Vals += SerialSend.ReadRegister(Convert.ToUInt32(XChipHDR.Find(c => c.NameType.Contains("gain_L_l")).Address, 16), sPortTemp).ToString("X2");
            //Vals += SerialSend.ReadRegister(Convert.ToUInt32(XChipHDR.Find(c => c.NameType.Contains("gain_L_h")).Address, 16), sPortTemp).ToString("X2");
            //gain_L.Text = Vals;
            //var mstr = modeSelRadio.SelectedIndex == 0 ? "hl" : "ll";
            var mstr = "hl";
            //comb_weight_LS_00.Text = GetRegister($"comb_weight_LS_{mstr}_00").ToString("X2");
            //comb_weight_LS_01.Text = GetRegister($"comb_weight_LS_{mstr}_01").ToString("X2");
            //comb_weight_LS_02.Text = GetRegister($"comb_weight_LS_{mstr}_02").ToString("X2");
            //comb_weight_LS_03.Text = GetRegister($"comb_weight_LS_{mstr}_03").ToString("X2");

            //comb_weight_LS_10.Text = GetRegister($"comb_weight_LS_{mstr}_10").ToString("X2");
            //comb_weight_LS_11.Text = GetRegister($"comb_weight_LS_{mstr}_11").ToString("X2");
            //comb_weight_LS_12.Text = GetRegister($"comb_weight_LS_{mstr}_12").ToString("X2");
            //comb_weight_LS_13.Text = GetRegister($"comb_weight_LS_{mstr}_13").ToString("X2");

            //comb_weight_LS_20.Text = GetRegister($"comb_weight_LS_{mstr}_20").ToString("X2");
            //comb_weight_LS_21.Text = GetRegister($"comb_weight_LS_{mstr}_21").ToString("X2");
            //comb_weight_LS_22.Text = GetRegister($"comb_weight_LS_{mstr}_22").ToString("X2");
            //comb_weight_LS_23.Text = GetRegister($"comb_weight_LS_{mstr}_23").ToString("X2");

            //comb_weight_LS_30.Text = GetRegister($"comb_weight_LS_{mstr}_30").ToString("X2");
            //comb_weight_LS_31.Text = GetRegister($"comb_weight_LS_{mstr}_31").ToString("X2");
            //comb_weight_LS_32.Text = GetRegister($"comb_weight_LS_{mstr}_32").ToString("X2");
            //comb_weight_LS_33.Text = GetRegister($"comb_weight_LS_{mstr}_33").ToString("X2");

            //comb_weight_LSV_00.Text = GetRegister($"comb_weight_LSV_{mstr}_00").ToString("X2");
            //comb_weight_LSV_01.Text = GetRegister($"comb_weight_LSV_{mstr}_01").ToString("X2");
            //comb_weight_LSV_02.Text = GetRegister($"comb_weight_LSV_{mstr}_02").ToString("X2");
            //comb_weight_LSV_03.Text = GetRegister($"comb_weight_LSV_{mstr}_03").ToString("X2");

            //comb_weight_LSV_10.Text = GetRegister($"comb_weight_LSV_{mstr}_10").ToString("X2");
            //comb_weight_LSV_11.Text = GetRegister($"comb_weight_LSV_{mstr}_11").ToString("X2");
            //comb_weight_LSV_12.Text = GetRegister($"comb_weight_LSV_{mstr}_12").ToString("X2");
            //comb_weight_LSV_13.Text = GetRegister($"comb_weight_LSV_{mstr}_13").ToString("X2");

            //comb_weight_LSV_20.Text = GetRegister($"comb_weight_LSV_{mstr}_20").ToString("X2");
            //comb_weight_LSV_21.Text = GetRegister($"comb_weight_LSV_{mstr}_21").ToString("X2");
            //comb_weight_LSV_22.Text = GetRegister($"comb_weight_LSV_{mstr}_22").ToString("X2");
            //comb_weight_LSV_23.Text = GetRegister($"comb_weight_LSV_{mstr}_23").ToString("X2");

            //comb_weight_LSV_30.Text = GetRegister($"comb_weight_LSV_{mstr}_30").ToString("X2");
            //comb_weight_LSV_31.Text = GetRegister($"comb_weight_LSV_{mstr}_31").ToString("X2");
            //comb_weight_LSV_32.Text = GetRegister($"comb_weight_LSV_{mstr}_32").ToString("X2");
            //comb_weight_LSV_33.Text = GetRegister($"comb_weight_LSV_{mstr}_33").ToString("X2");
            //#endregion
            //var combine = SerialSend.ReadRegister((Convert.ToUInt32(hdrList.Where(c => c.NameType.ToLower() == "combine_mode_en".ToLower()).First().Address, 16)), sPortTemp);
            //if (combine == 0x80)
            //{
            //    Mode_switch.Properties.Items[3].Enabled = false;
            //}
            //else if (combine == 0xC0)
            //{
            //    Mode_switch.Properties.Items[3].Enabled = true;
            //}
            var HDRmodeVal = SerialSend.ReadRegister(Convert.ToUInt32(hdrList.Where(c => c.NameType.ToLower() == "HDRmode0".ToLower()).First().Address, 16), sPortTemp).ToString("X");
            bool HDRmode0 = BitsHelp.GetBitsCheckedToBool(hdrList.Where(c => c.NameType.ToLower() == "HDRmode0".ToLower()).First().Bits, hdrList.Where(c => c.NameType.ToLower() == "HDRmode0".ToLower()).First().Hex, HDRmodeVal) == 0;
            HDRmodeVal = SerialSend.ReadRegister(Convert.ToUInt32(hdrList.Where(c => c.NameType.ToLower() == "HDRmode1".ToLower()).First().Address, 16), sPortTemp).ToString("X");
            bool HDRmode1 = BitsHelp.GetBitsCheckedToBool(hdrList.Where(c => c.NameType.ToLower() == "HDRmode1".ToLower()).First().Bits, hdrList.Where(c => c.NameType.ToLower() == "HDRmode1".ToLower()).First().Hex, HDRmodeVal) == 0;
            HDRmodeVal = SerialSend.ReadRegister(Convert.ToUInt32(hdrList.Where(c => c.NameType.ToLower() == "HDRmode2".ToLower()).First().Address, 16), sPortTemp).ToString("X");
            bool HDRmode2 = BitsHelp.GetBitsCheckedToBool(hdrList.Where(c => c.NameType.ToLower() == "HDRmode2".ToLower()).First().Bits, hdrList.Where(c => c.NameType.ToLower() == "HDRmode2".ToLower()).First().Hex, HDRmodeVal) == 0;
            //if (HDRmode0 && !HDRmode1 && !HDRmode1)
            //{
            //    Mode_switch.SelectedIndex = 0;
            //}
            //else if (!HDRmode0 && !HDRmode1 && !HDRmode2)
            //{
            //    Mode_switch.SelectedIndex = 1;
            //}
            //else if (!HDRmode0 && HDRmode1 && !HDRmode2)
            //{
            //    Mode_switch.SelectedIndex = 2;
            //}
            //else if (!HDRmode0 && !HDRmode1 && HDRmode2)
            //{
            //    Mode_switch.SelectedIndex = 3;
            //}
            //Statusvalue();

            isRead = false;
            WaitBefore.Close();
        }
        private void Statusvalue()
        {
            //if (tome_mapping_en.Checked)
            //{
            //    hist_thr_highlight.Enabled = false;
            //}
            //else
            //{
            //    hist_thr_highlight.Enabled = true;
            //}
            //if (combine_preferLong_en.Checked)
            //{
            //    weight_hds_en.Enabled = true;
            //    weight_gain_en.Enabled = true;
            //    weight_man_en.Enabled = true;
            //}
            //else
            //{
            //    weight_hds_en.Enabled = false;
            //    weight_gain_en.Enabled = false;
            //    weight_man_en.Enabled = false;
            //}
            //if (weight_hds_en.Checked || weight_gain_en.Checked || weight_man_en.Checked)
            //{
            //    combine_preferLong_str.Enabled = false;
            //}
            //else
            //{
            //    combine_preferLong_str.Enabled = true;
            //}
        }
        private void combwt_man_en_CheckedChanged(object sender, EventArgs e)
        {
            var chk = sender as CheckEdit;
            if (isRead) return;
            if (XChipHDR.Exists(c => c.NameType.ToLower() == (chk.Name).ToLower()))
            {
                var model = XChipHDR.Find(c => c.NameType.ToLower() == (chk.Name).ToLower());
                var Add = SerialSend.ReadRegister(Convert.ToUInt32(model.Address, 16), sPortTemp);
                var Val = BitsHelp.SetBitsCheckedToUint(model.Bits, model.Hex, Add.ToString("X2"), chk.Checked);
                SetHDRRegister(model, Val);
            }
        }

        private void combine_preferLong_en_CheckedChanged(object sender, EventArgs e)
        {
            var chk = sender as CheckEdit;
            if (isRead) return;
            if (XChipHDR.Exists(c => c.NameType.ToLower() == (chk.Name).ToLower()))
            {
                var model = XChipHDR.Find(c => c.NameType.ToLower() == (chk.Name).ToLower());
                var Add = SerialSend.ReadRegister(Convert.ToUInt32(model.Address, 16), sPortTemp);
                var Val = BitsHelp.SetBitsCheckedToUint(model.Bits, model.Hex, Add.ToString("X2"), chk.Checked);
                SetHDRRegister(model, Val);
            }
            Statusvalue();
        }

        private void combwt_man_Leave(object sender, EventArgs e)
        {
            if (isWrite) return;
            var txtedit = sender as DevExpress.XtraEditors.TextEdit;
            if (string.IsNullOrEmpty(txtedit.Text)) return;
            //SetSDERegister("SDE_SATV", (ulong)Convert.ToInt32(txtedit.Text, 16));
            if (XChipHDR.Exists(c => c.NameType.ToLower() == txtedit.Name.ToLower()))
            {
                var model = XChipHDR.Find(c => c.NameType.ToLower() == txtedit.Name.ToLower());
                var Val = BitsHelp.SetBitsToUint(model.Bits, model.Hex, txtedit.Text);
                SetHDRRegister(model, Val);
            }
        }

        private void combine_preferLong_Leave(object sender, EventArgs e)
        {
            if (isWrite) return;
            var txtedit = sender as DevExpress.XtraEditors.TextEdit;
            if (string.IsNullOrEmpty(txtedit.Text)) return;
            if (XChipHDR.Exists(c => c.NameType.ToLower() == txtedit.Name.ToLower()))
            {
                var model = XChipHDR.Find(c => c.NameType.ToLower() == txtedit.Name.ToLower());
                var Val = BitsHelp.SetBitsToUint(model.Bits, model.Hex, txtedit.Text);
                SetHDRRegister(model, Val);
            }
        }

        private void combwt_man_KeyDown(object sender, KeyEventArgs e)
        {
            if (e.KeyCode == Keys.Enter)
            {
                combwt_man_Leave(sender, null);
            }
        }

        private void combine_preferLong_KeyDown(object sender, KeyEventArgs e)
        {
            if (e.KeyCode == Keys.Enter)
            {
                combine_preferLong_Leave(sender, null);
            }
        }

        private void Mode_switch_SelectedIndexChanged(object sender, EventArgs e)
        {
            //if (Mode_switch.EditValue.ToString() == "1")
            //{
            //    if (XChipHDR.Exists(c => c.NameType.ToLower() == "HDRmode0".ToLower()))
            //    {
            //        var model = XChipHDR.Find(c => c.NameType.ToLower() == "HDRmode0".ToLower());
            //        //var Val = BitsHelp.SetBitsToUint(model.Bits, model.Hex,"1");
            //        var Add = SerialSend.ReadRegister(Convert.ToUInt32(model.Address, 16), sPortTemp);
            //        var Val = BitsHelp.SetBitsCheckedToUint(model.Bits, model.Hex, Add.ToString("X2"), true);
            //        SetHDRRegister(model, Val);
            //    }
            //    if (XChipHDR.Exists(c => c.NameType.ToLower() == "HDRmode1".ToLower()))
            //    {
            //        var model = XChipHDR.Find(c => c.NameType.ToLower() == "HDRmode1".ToLower());
            //        //var Val = BitsHelp.SetBitsCheckedToUint(model.Bits, model.Hex, "0");
            //        var Add = SerialSend.ReadRegister(Convert.ToUInt32(model.Address, 16), sPortTemp);
            //        var Val = BitsHelp.SetBitsCheckedToUint(model.Bits, model.Hex, Add.ToString("X2"), false);
            //        SetHDRRegister(model, Val);
            //    }
            //    if (XChipHDR.Exists(c => c.NameType.ToLower() == "HDRmode2".ToLower()))
            //    {
            //        var model = XChipHDR.Find(c => c.NameType.ToLower() == "HDRmode2".ToLower());
            //        //var Val = BitsHelp.SetBitsCheckedToUint(model.Bits, model.Hex, "0");
            //        var Add = SerialSend.ReadRegister(Convert.ToUInt32(model.Address, 16), sPortTemp);
            //        var Val = BitsHelp.SetBitsCheckedToUint(model.Bits, model.Hex, Add.ToString("X2"), false);
            //        SetHDRRegister(model, Val);
            //    }
            //}
            //else if (Mode_switch.EditValue.ToString() == "2")
            //{
            //    if (XChipHDR.Exists(c => c.NameType.ToLower() == "HDRmode0".ToLower()))
            //    {
            //        var model = XChipHDR.Find(c => c.NameType.ToLower() == "HDRmode0".ToLower());
            //        //var Val = BitsHelp.SetBitsToUint(model.Bits, model.Hex, "0");
            //        var Add = SerialSend.ReadRegister(Convert.ToUInt32(model.Address, 16), sPortTemp);
            //        var Val = BitsHelp.SetBitsCheckedToUint(model.Bits, model.Hex, Add.ToString("X2"), false);
            //        SetHDRRegister(model, Val);
            //    }
            //    if (XChipHDR.Exists(c => c.NameType.ToLower() == "HDRmode1".ToLower()))
            //    {
            //        var model = XChipHDR.Find(c => c.NameType.ToLower() == "HDRmode1".ToLower());
            //        //var Val = BitsHelp.SetBitsToUint(model.Bits, model.Hex, "0");
            //        var Add = SerialSend.ReadRegister(Convert.ToUInt32(model.Address, 16), sPortTemp);
            //        var Val = BitsHelp.SetBitsCheckedToUint(model.Bits, model.Hex, Add.ToString("X2"), false);
            //        SetHDRRegister(model, Val);
            //    }
            //    if (XChipHDR.Exists(c => c.NameType.ToLower() == "HDRmode2".ToLower()))
            //    {
            //        var model = XChipHDR.Find(c => c.NameType.ToLower() == "HDRmode2".ToLower());
            //        //var Val = BitsHelp.SetBitsToUint(model.Bits, model.Hex, "0");
            //        var Add = SerialSend.ReadRegister(Convert.ToUInt32(model.Address, 16), sPortTemp);
            //        var Val = BitsHelp.SetBitsCheckedToUint(model.Bits, model.Hex, Add.ToString("X2"), false);
            //        SetHDRRegister(model, Val);
            //    }
            //}
            //else if (Mode_switch.EditValue.ToString() == "3")
            //{
            //    if (XChipHDR.Exists(c => c.NameType.ToLower() == "HDRmode0".ToLower()))
            //    {
            //        var model = XChipHDR.Find(c => c.NameType.ToLower() == "HDRmode0".ToLower());
            //        // var Val = BitsHelp.SetBitsToUint(model.Bits, model.Hex, "0");
            //        var Add = SerialSend.ReadRegister(Convert.ToUInt32(model.Address, 16), sPortTemp);
            //        var Val = BitsHelp.SetBitsCheckedToUint(model.Bits, model.Hex, Add.ToString("X2"), false);
            //        SetHDRRegister(model, Val);
            //    }
            //    if (XChipHDR.Exists(c => c.NameType.ToLower() == "HDRmode1".ToLower()))
            //    {
            //        var model = XChipHDR.Find(c => c.NameType.ToLower() == "HDRmode1".ToLower());
            //        // var Val = BitsHelp.SetBitsToUint(model.Bits, model.Hex, "1");
            //        var Add = SerialSend.ReadRegister(Convert.ToUInt32(model.Address, 16), sPortTemp);
            //        var Val = BitsHelp.SetBitsCheckedToUint(model.Bits, model.Hex, Add.ToString("X2"), true);
            //        SetHDRRegister(model, Val);
            //    }
            //    if (XChipHDR.Exists(c => c.NameType.ToLower() == "HDRmode2".ToLower()))
            //    {
            //        var model = XChipHDR.Find(c => c.NameType.ToLower() == "HDRmode2".ToLower());
            //        // var Val = BitsHelp.SetBitsToUint(model.Bits, model.Hex, "0");
            //        var Add = SerialSend.ReadRegister(Convert.ToUInt32(model.Address, 16), sPortTemp);
            //        var Val = BitsHelp.SetBitsCheckedToUint(model.Bits, model.Hex, Add.ToString("X2"), false);
            //        SetHDRRegister(model, Val);
            //    }
            //}
            //else if (Mode_switch.EditValue.ToString() == "4")
            //{
            //    if (XChipHDR.Exists(c => c.NameType.ToLower() == "HDRmode0".ToLower()))
            //    {
            //        var model = XChipHDR.Find(c => c.NameType.ToLower() == "HDRmode0".ToLower());
            //        //var Val = BitsHelp.SetBitsToUint(model.Bits, model.Hex, "0");
            //        var Add = SerialSend.ReadRegister(Convert.ToUInt32(model.Address, 16), sPortTemp);
            //        var Val = BitsHelp.SetBitsCheckedToUint(model.Bits, model.Hex, Add.ToString("X2"), false);
            //        SetHDRRegister(model, Val);
            //    }
            //    if (XChipHDR.Exists(c => c.NameType.ToLower() == "HDRmode1".ToLower()))
            //    {
            //        var model = XChipHDR.Find(c => c.NameType.ToLower() == "HDRmode1".ToLower());
            //        //var Val = BitsHelp.SetBitsToUint(model.Bits, model.Hex, "0");
            //        var Add = SerialSend.ReadRegister(Convert.ToUInt32(model.Address, 16), sPortTemp);
            //        var Val = BitsHelp.SetBitsCheckedToUint(model.Bits, model.Hex, Add.ToString("X2"), false);
            //        SetHDRRegister(model, Val);
            //    }
            //    if (XChipHDR.Exists(c => c.NameType.ToLower() == "HDRmode2".ToLower()))
            //    {
            //        var model = XChipHDR.Find(c => c.NameType.ToLower() == "HDRmode2".ToLower());
            //        //var Val = BitsHelp.SetBitsToUint(model.Bits, model.Hex, "1");
            //        var Add = SerialSend.ReadRegister(Convert.ToUInt32(model.Address, 16), sPortTemp);
            //        var Val = BitsHelp.SetBitsCheckedToUint(model.Bits, model.Hex, Add.ToString("X2"), true);
            //        SetHDRRegister(model, Val);
            //    }
            //}
        }

        private void avg_list0_Leave(object sender, EventArgs e)
        {
            if (isWrite) return;
            //if (null != sPortTemp && sPortTemp.IsOpen)
            {
                if (isRead) return;
                var txt = sender as DevExpress.XtraEditors.TextEdit;
                if (string.IsNullOrEmpty(txt.Text)) return;
                if (XChipHDR.Exists(c => c.NameType.ToLower() == txt.Name.ToLower()))
                {
                    var model = XChipHDR.Find(c => c.NameType.ToLower() == txt.Name.ToLower());
                    var Val = BitsHelp.SetBitsToUint(model.Bits, model.Hex, txt.Text);
                    SetHDRRegister(model, Val);
                }
            }
        }

        private void avg_wave_Leave(object sender, EventArgs e)
        {
            if (isWrite) return;
            //if (null != sPortTemp && sPortTemp.IsOpen)
            {
                if (isRead) return;
                var txt = sender as DevExpress.XtraEditors.TextEdit;
                if (string.IsNullOrEmpty(txt.Text)) return;
                if (XChipHDR.Exists(c => c.NameType.ToLower() == txt.Name.ToLower()))
                {
                    var model = XChipHDR.Find(c => c.NameType.ToLower() == txt.Name.ToLower());
                    var Val = BitsHelp.SetBitsToUint(model.Bits, model.Hex, txt.Text);
                    SetHDRRegister(model, Val);
                }
            }
        }

        private void gamma_ratiolist0_Leave(object sender, EventArgs e)
        {
            if (isWrite) return;
            //if (null != sPortTemp && sPortTemp.IsOpen)
            {
                if (isRead) return;
                var txt = sender as DevExpress.XtraEditors.TextEdit;
                if (string.IsNullOrEmpty(txt.Text)) return;
                if (XChipHDR.Exists(c => c.NameType.ToLower() == txt.Name.ToLower()))
                {
                    var model = XChipHDR.Find(c => c.NameType.ToLower() == txt.Name.ToLower());
                    var Val = BitsHelp.SetBitsToUint(model.Bits, model.Hex, txt.Text);
                    SetHDRRegister(model, Val);
                }
            }
        }

        private void weight_gainlist0_Leave(object sender, EventArgs e)
        {
            if (isWrite) return;
            //if (null != sPortTemp && sPortTemp.IsOpen)
            {
                if (isRead) return;
                var txt = sender as DevExpress.XtraEditors.TextEdit;
                if (string.IsNullOrEmpty(txt.Text)) return;
                if (XChipHDR.Exists(c => c.NameType.ToLower() == txt.Name.ToLower()))
                {
                    var model = XChipHDR.Find(c => c.NameType.ToLower() == txt.Name.ToLower());
                    var Val = BitsHelp.SetBitsToUint(model.Bits, model.Hex, txt.Text);
                    SetHDRRegister(model, Val);
                }
            }
        }

        private void weight_man_Leave(object sender, EventArgs e)
        {
            if (isWrite) return;
            //if (null != sPortTemp && sPortTemp.IsOpen)
            {
                if (isRead) return;
                var txt = sender as DevExpress.XtraEditors.TextEdit;
                if (string.IsNullOrEmpty(txt.Text)) return;
                if (XChipHDR.Exists(c => c.NameType.ToLower() == txt.Name.ToLower()))
                {
                    var model = XChipHDR.Find(c => c.NameType.ToLower() == txt.Name.ToLower());
                    var Val = BitsHelp.SetBitsToUint(model.Bits, model.Hex, txt.Text);
                    SetHDRRegister(model, Val);
                }
            }
        }

        private void threshold_l_Leave(object sender, EventArgs e)
        {
            if (isWrite) return;
            //if (null != sPortTemp && sPortTemp.IsOpen)
            {
                if (isRead) return;
                var txt = sender as DevExpress.XtraEditors.TextEdit;
                if (string.IsNullOrEmpty(txt.Text)) return;
                if (XChipHDR.Exists(c => c.NameType.ToLower() == txt.Name.ToLower() + "_h"))
                {
                    var model = XChipHDR.Find(c => c.NameType.ToLower() == (txt.Name + "_h").ToLower());
                    var Val = BitsHelp.SetBitsToUint(model.Bits, model.Hex, txt.Text);
                    SetHDRRegister(model, Val);
                }
                if (XChipHDR.Exists(c => c.NameType.ToLower() == txt.Name.ToLower() + "_l"))
                {
                    var model = XChipHDR.Find(c => c.NameType.ToLower() == (txt.Name + "_l").ToLower());
                    var Val = BitsHelp.SetBitsToUint(model.Bits, model.Hex, txt.Text);
                    SetHDRRegister(model, Val);
                }
            }
        }

        private void tome_mappinglist0_Leave(object sender, EventArgs e)
        {
            if (isWrite) return;
            //if (null != sPortTemp && sPortTemp.IsOpen)
            {
                if (isRead) return;
                var txt = sender as DevExpress.XtraEditors.TextEdit;
                if (string.IsNullOrEmpty(txt.Text)) return;
                if (XChipHDR.Exists(c => c.NameType.ToLower() == txt.Name.ToLower() + "_h"))
                {
                    var model = XChipHDR.Find(c => c.NameType.ToLower() == (txt.Name + "_h").ToLower());
                    var Val = BitsHelp.SetBitsToUint(model.Bits, model.Hex, txt.Text);
                    SetHDRRegister(model, Val);
                }
                if (XChipHDR.Exists(c => c.NameType.ToLower() == txt.Name.ToLower() + "_l"))
                {
                    var model = XChipHDR.Find(c => c.NameType.ToLower() == (txt.Name + "_l").ToLower());
                    var Val = BitsHelp.SetBitsToUint(model.Bits, model.Hex, txt.Text);
                    SetHDRRegister(model, Val);
                }
            }
        }

        private void avg_wave_KeyDown(object sender, KeyEventArgs e)
        {
            if (e.KeyCode == Keys.Enter)
            {
                avg_wave_Leave(sender, null);
            }
        }

        private void avg_list0_KeyDown(object sender, KeyEventArgs e)
        {
            if (e.KeyCode == Keys.Enter)
            {
                avg_list0_Leave(sender, null);
            }
        }

        private void gamma_ratiolist0_KeyDown(object sender, KeyEventArgs e)
        {
            if (e.KeyCode == Keys.Enter)
            {
                gamma_ratiolist0_Leave(sender, null);
            }
        }

        private void tome_mappinglist0_KeyDown(object sender, KeyEventArgs e)
        {
            if (e.KeyCode == Keys.Enter)
            {
                tome_mappinglist0_Leave(sender, null);
            }
        }

        private void threshold_l_KeyDown(object sender, KeyEventArgs e)
        {
            if (e.KeyCode == Keys.Enter)
            {
                threshold_l_Leave(sender, null);
            }
        }

        private void threshold_h_KeyDown(object sender, KeyEventArgs e)
        {
            if (e.KeyCode == Keys.Enter)
            {
                threshold_l_Leave(sender, null);
            }
        }

        private void threshold_num_Leave(object sender, EventArgs e)
        {
            if (isWrite) return;
            //if (null != sPortTemp && sPortTemp.IsOpen)
            {
                if (isRead) return;
                var txt = sender as DevExpress.XtraEditors.TextEdit;
                if (string.IsNullOrEmpty(txt.Text)) return;
                if (XChipHDR.Exists(c => c.NameType.ToLower() == txt.Name.ToLower()))
                {
                    var model = XChipHDR.Find(c => c.NameType.ToLower() == txt.Name.ToLower());
                    var Val = BitsHelp.SetBitsToUint(model.Bits, model.Hex, txt.Text);
                    SetHDRRegister(model, Val);
                }
            }
        }

        private void threshold_num_KeyDown(object sender, KeyEventArgs e)
        {
            if (e.KeyCode == Keys.Enter)
            {
                threshold_num_Leave(sender, null);
            }
        }

        private void weight_gainlist0_KeyDown(object sender, KeyEventArgs e)
        {
            if (e.KeyCode == Keys.Enter)
            {
                weight_gainlist0_Leave(sender, null);
            }
        }

        private void weight_man_KeyDown(object sender, KeyEventArgs e)
        {
            if (e.KeyCode == Keys.Enter)
            {
                weight_man_Leave(sender, null);
            }
        }

        private void weight_gain_en_CheckedChanged(object sender, EventArgs e)
        {
            var chk = sender as CheckEdit;
            if (isRead) return;
            if (XChipHDR.Exists(c => c.NameType.ToLower() == (chk.Name).ToLower()))
            {
                var model = XChipHDR.Find(c => c.NameType.ToLower() == (chk.Name).ToLower());
                var Add = SerialSend.ReadRegister(Convert.ToUInt32(model.Address, 16), sPortTemp);
                var Val = BitsHelp.SetBitsCheckedToUint(model.Bits, model.Hex, Add.ToString("X2"), chk.Checked);
                SetHDRRegister(model, Val);
            }
            Statusvalue();
        }

        private void tome_mapping_en_CheckedChanged(object sender, EventArgs e)
        {
            var chk = sender as CheckEdit;
            if (isRead) return;
            if (XChipHDR.Exists(c => c.NameType.ToLower() == (chk.Name).ToLower()))
            {
                var model = XChipHDR.Find(c => c.NameType.ToLower() == (chk.Name).ToLower());
                var Add = SerialSend.ReadRegister(Convert.ToUInt32(model.Address, 16), sPortTemp);
                var Val = BitsHelp.SetBitsCheckedToUint(model.Bits, model.Hex, Add.ToString("X2"), chk.Checked);
                SetHDRRegister(model, Val);
            }
            Statusvalue();
        }

        private void weight_hds_en_CheckedChanged(object sender, EventArgs e)
        {
            var chk = sender as CheckEdit;
            if (isRead) return;
            if (XChipHDR.Exists(c => c.NameType.ToLower() == (chk.Name).ToLower()))
            {
                var model = XChipHDR.Find(c => c.NameType.ToLower() == (chk.Name).ToLower());
                var Add = SerialSend.ReadRegister(Convert.ToUInt32(model.Address, 16), sPortTemp);
                var Val = BitsHelp.SetBitsCheckedToUint(model.Bits, model.Hex, Add.ToString("X2"), chk.Checked);
                SetHDRRegister(model, Val);
            }
            Statusvalue();
        }

        private void gamma_ratio_en_CheckedChanged(object sender, EventArgs e)
        {
            var chk = sender as CheckEdit;
            if (isRead) return;
            if (XChipHDR.Exists(c => c.NameType.ToLower() == (chk.Name).ToLower()))
            {
                var model = XChipHDR.Find(c => c.NameType.ToLower() == (chk.Name).ToLower());
                var Add = SerialSend.ReadRegister(Convert.ToUInt32(model.Address, 16), sPortTemp);
                var Val = BitsHelp.SetBitsCheckedToUint(model.Bits, model.Hex, Add.ToString("X2"), chk.Checked);
                SetHDRRegister(model, Val);
            }
        }

        private void weight_man_en_CheckedChanged(object sender, EventArgs e)
        {
            var chk = sender as CheckEdit;
            if (isRead) return;
            if (XChipHDR.Exists(c => c.NameType.ToLower() == (chk.Name).ToLower()))
            {
                var model = XChipHDR.Find(c => c.NameType.ToLower() == (chk.Name).ToLower());
                var Add = SerialSend.ReadRegister(Convert.ToUInt32(model.Address, 16), sPortTemp);
                var Val = BitsHelp.SetBitsCheckedToUint(model.Bits, model.Hex, Add.ToString("X2"), chk.Checked);
                SetHDRRegister(model, Val);
            }
            Statusvalue();
        }

        private void XChip_HDR_Load(object sender, EventArgs e)
        {
            Task.Run(() => {
                this.Invoke((EventHandler)delegate {
                    for (int i = 0; i < XChipHDR.Count; i++)
                    {

                        var type = AppHelper.NameTypeToString(XChipHDR[i].NameType);

                        var col = this.Controls.Find(type, true);


                        foreach (var item in col)
                        {
                            if (item is TextEdit)
                            {
                                //声明一个SuerToolTip
                                DevExpress.Utils.SuperToolTip graduationBatchSuperToolTip = new DevExpress.Utils.SuperToolTip();
                                //声明一个ToolTipTitleItem,保存标题
                                DevExpress.Utils.ToolTipTitleItem toolTipTitleItem = new DevExpress.Utils.ToolTipTitleItem();
                                String tooltips = "";
                                if (!string.IsNullOrEmpty(XChipHDR[i].Bit_Wide))
                                {
                                    tooltips += $"位宽={XChipHDR[i].Bit_Wide}";
                                }
                                if (!string.IsNullOrEmpty(XChipHDR[i].Bit_Accuracy))
                                {
                                    tooltips += $"|精度={XChipHDR[i].Bit_Accuracy}";
                                }
                                //设置标题文字
                                toolTipTitleItem.Text = tooltips;
                                //把标题添加到SuerToolTip
                                graduationBatchSuperToolTip.Items.Add(toolTipTitleItem);
                                //指定控件的SuperTip
                                ((TextEdit)item).SuperTip = graduationBatchSuperToolTip;
                                //正则判断
                                ((TextEdit)item).Properties.Mask.MaskType = DevExpress.XtraEditors.Mask.MaskType.RegEx;
                                ((TextEdit)item).Properties.Mask.EditMask = BitsHelp.GetBitsToMask(XChipHDR[i].Bits, XChipHDR[i].Bit_Wide, XChipHDR.Where(c => c.NameType.ToLower().Contains(type) && c.ControlType == "0").Select(c => c.Bits).ToList());
                            }
                        }

                    }

                    xChip_HDR_Ae = new XChip_Lite_HDR_Ae(sPortTemp, aBll, IsUsbOpen);
                    xChip_HDR_Ae.Dock = DockStyle.Fill;
                    xChip_HDR_Ae.Name = "XChip_Lite_HDR_Ae";
                    this.tabNavigationPage1.Controls.Add(xChip_HDR_Ae);
                    this.tabNavigationPage1.Name = "XChip_Lite_HDR_AePage";
                });
            });
        }

        private void simpleButton1_Click(object sender, EventArgs e)
        {
            //ratio_highlight.Text = GetRegister("ratio_highlight", hdrList).ToString("X2");
            ////ratio_lowlight.Text = GetRegister("ratio_lowlight", hdrList).ToString("X2");
            //string Vals = string.Empty;
            //Vals += SerialSend.ReadRegister(Convert.ToUInt32(hdrList.Find(c => c.NameType.Contains("portion_highlight_h")).Address, 16), sPortTemp).ToString("X2");
            //Vals += SerialSend.ReadRegister(Convert.ToUInt32(hdrList.Find(c => c.NameType.Contains("portion_highlight_l")).Address, 16), sPortTemp).ToString("X2");
            //portion_lighlight.Text = Vals;
        }

        private void simpleButton10_Click(object sender, EventArgs e)
        {

        }

        private void ratio_highlight_Leave(object sender, EventArgs e)
        {
            //if (isRead) return;
            //if (string.IsNullOrEmpty(ratio_highlight.Text)) return;
            //if (hdrList.Count == 0)
            //{
            //    if (null == addrDal)
            //    {
            //        addrDal = new addressregisterManager();
            //    }
            //    hdrList = addrDal.GetList(c => c.Classify.Contains("hdr"));
            //}
            //SetRegister("ratio_highlight", Convert.ToUInt32(ratio_highlight.Text, 16), hdrList);
        }

        private void ratio_highlight_KeyDown(object sender, KeyEventArgs e)
        {
            if (e.KeyCode == Keys.Enter)
            {
                ratio_highlight_Leave(sender, null);
            }
        }

        private void portion_lighlight_Leave(object sender, EventArgs e)
        {
            if (isRead) return;
            if (null != sPortTemp || !IsUsbOpen || !m_open)
            {

                if (isRead) return;
                var txt = sender as DevExpress.XtraEditors.TextEdit;
                if (string.IsNullOrEmpty(txt.Text)) return;
                if (null == addrDal)
                {
                    addrDal = new addressregisterManager();
                }
                hdrList = addrDal.GetList(c => c.Classify.Contains("hdr"));
                if (hdrList.Exists(c => c.NameType.ToLower() == "portion_highlight".ToLower() + "_h"))
                {
                    var model = hdrList.Find(c => c.NameType.ToLower() == ("portion_highlight" + "_h").ToLower());
                    var Val = BitsHelp.SetBitsToUint(model.Bits, model.Hex, txt.Text);
                    SetHDRRegister(model, Val);
                }
                if (hdrList.Exists(c => c.NameType.ToLower() == "portion_highlight".ToLower() + "_l"))
                {
                    var model = hdrList.Find(c => c.NameType.ToLower() == ("portion_highlight" + "_l").ToLower());
                    var Val = BitsHelp.SetBitsToUint(model.Bits, model.Hex, txt.Text);
                    SetHDRRegister(model, Val);
                }
            }
        }

        private void portion_lighlight_KeyDown(object sender, KeyEventArgs e)
        {
            if (e.KeyCode == Keys.Enter)
            {
                portion_lighlight_Leave(sender, null);
            }
        }
    }
}
